/** 
 * storage二次封装
 * @author lls
 */
import config from './../config';

export default {
  setItem (key, val) {
    let storage = this.getStorage()
    storage[key] = val
    window.localStorage.setItem(config.nameSpace, JSON.stringify(storage))
  },
  getItem (key) {
    return this.getStorage()[key] 
  },
  getStorage () {
    return JSON.parse(window.localStorage.getItem(config.nameSpace) || "{}")
  },
  clearItem (key) {
    let storage = this.getStorage()
    delete storage[key]
    window.localStorage.setItem(config.nameSpace, JSON.stringify(storage))
  },
  clearAll () {
    window.localStorage.clear() 
  }
}